from transitions import Machine

class StringExtractor:
    states=['search','inside','skip']
    def __init__(self, file_path):
        self.machine=Machine(model=self,states=StringExtractor.states,initial="search")
        self.machine.add_transition(trigger='search_to_inside',source="search",dest="inside")
        self.machine.add_transition(trigger='inside_to_search',source="inside",dest="search")
        self.machine.add_transition(trigger='inside_to_skip',source="inside",dest="skip")
        self.machine.add_transition(trigger='skip_to_inside',source="skip",dest="inside")
        self.file_path = file_path
        with open(self.file_path, 'r',encoding='utf-8') as file:
            self.content = file.read()
        self.strings = []
        self.string=""
    def cheak(self,s):
        if s=='"' and self.state=="search":
            self.search_to_inside()
        elif self.state=="inside" and s=='"':
            self.inside_to_search()
            self.strings.append(self.string)
            self.string=''
        elif self.state=="inside"and s=="\\":
            self.inside_to_skip()
        elif self.state=="skip":
            self.skip_to_inside()
    def run(self):
        for s in self.content:
            # print(s,self.state)
            if self.state=="inside":
                self.cheak(s)
                if s!='"' and s!="\\":
                    self.string+=s
            elif self.state=="search":
                self.cheak(s)
            elif self.state=="skip":
                self.string += s
                self.cheak(s)
        print(self.strings)

extractor = StringExtractor('test')
print(extractor.content)
extractor.run()